package com.itheima.mapper;

import com.itheima.domain.Category;
import com.itheima.domain.Route;
import com.itheima.domain.RouteImg;
import com.itheima.domain.Seller;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RouteMapper {
    @Select("select * from tab_route where cid=#{cid}")
    List<Route> findByCid(Integer cid);

    @Results(value = {
            @Result(column = "rid",property = "rid"),
            @Result(column = "rname",property = "rname"),
            @Result(column = "price",property = "price"),
            @Result(column = "description",property = "description"),
            @Result(column = "num", property = "num"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "rimage", property = "rimage"),
            @Result(column = "sid", property = "sid"),
            @Result(column = "cid", property = "category",one = @One(select = "findCategoryByCid")),
            @Result(column = "sid", property = "seller",one = @One(select = "findSellerBySid")),
            @Result(column = "rid",property = "routeImgList",many = @Many(select = "findRouteImgListByRid")),
    })

    @Select("select * from tab_route where rid=#{rid} ")
    Route findRouteDetail(Integer rid);

    @Select("select * from tab_category where cid=#{cid}")
    Category findCategoryByCid(Integer cid);

    @Select("select * from tab_seller where sid=#{sid}")
    Seller findSellerBySid(Integer sid);

    @Select("select * from tab_route_img where rid=#{rid}")
    List<RouteImg> findRouteImgListByRid(Integer rid);
}
